<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title><spring:message code="message.lable.select"/><spring:message code="message.listForm.YaoLiFenLei"/></title>
<%@ include file="/WEB-INF/component/commonCSS.jsp" %>  
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class="form-inline">
                    
                    <div class="form-group form-group-xs">
                        <label for="searchPharName"><spring:message code="message.listForm.yaoLiFenLeiMingCheng"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <input class="form-control" type="text" id="searchPharName" placeholder="<spring:message code="message.listForm.yaoLiFenLeiMingCheng"/>" maxlength="50" />
                    </div>
                    
                    <div class="form-group form-group-xs">
                        <label for="searchPharCode"><spring:message code="message.listForm.yaoLiFenLeiBianMa"/><spring:message code="message.yanZheng.maoHao"/></label>
                        <input class="form-control" type="text" id="searchPharCode" placeholder="<spring:message code="message.listForm.yaoLiFenLeiBianMa"/>" maxlength="10" />
                    </div>
                    
                    <button type="button" class="btn btn-success btn-sm" onclick="search();" id="selectDrug"><spring:message code="message.button.seachSpacing"/></button>
                </div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
            <button type="button" id="confirm"  onclick="confirm();" class="btn btn-default btn-sm"><spring:message code="message.button.okSpacing"/></button>
        </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
    
  //绑定回车
    $('#searchPharCode,#searchPharName').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectDrug').click();
        }
    }); 
  
    $("#searchPharName").focus();//加载页面光标在第一个查询框内
	    	
	    	function search(page) {
	    		var pharCode = $("#searchPharCode").val();
	    		var pharName = $("#searchPharName").val();
	    		$("#gridlist").jqGrid('setGridParam',{  
	    	        datatype:'json',
	    	        postData:{"pharCode":pharCode, "pharName":pharName},
	    	        page : (page || 1)
	    	    }).trigger("reloadGrid"); //重新载入  
	    	}
	    
	        $(function () {
	        	
	            $("#gridlist").jqGrid({
	                url: "${ctx}/stdProdDrugInfo/getSelectPhar.html",
	                mtype: "POST",
	                datatype: "json",
	                autowidth: true,
	                height: 270,
	                colNames: [ 
	                            'pharId',
	                            '<spring:message code="message.listForm.yaoLiFenLeiBianMa"/>',
	                            '<spring:message code="message.listForm.yaoLiFenLeiMingCheng"/>'
	                            ],
	                colModel: [
						{ name: 'pharId', width: 10,hidden:true, align:"center", sortable: false},
	                    { name: 'pharCode', width: 10, align:"center", sortable: false},
	                    { name: 'pharName', width: 10, align:"center", sortable: false }
	                ],
	                rowNum: 20,
	                rowList: [10, 20, 50,100],
	                rownumbers: true,
	                pager: "#gridpage",
	                viewrecords: true,
	                caption: "<spring:message code="message.list.pharDiclist"/>",
	              //序号宽度自动变化
	                gridComplete:function(){
	                    //序号列宽度自适应（参数为jqgridID）
	                    autoRNWidth("gridlist");
	                    //数据只有一条时默认选中（参数为jqgridID）
	                    selectByOneData("gridlist");
	                },
	                jsonReader: {
	                    id: "pharId"
	                }
                    /* gridComplete:function(){        
                        var page = $("#gridlist").jqGrid('getGridParam','page');
                        var rows = $('#gridlist').getGridParam("rowNum");
                        var maxnum = (rows*page).toString();
                        var len = (maxnum.length)*10;
                        $('.jqgfirstrow').find('td').eq(0).css('width',len+'px');
                        $('#gridlist_rn').css('width',len+'px');
                        
                        selectByOneData("gridlist");
                    } */
	            });
	            
	            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
	            $(window).trigger("resize");
	          
	        });
	        
	      //确认
	        function confirm() {
	            var rowId = $("#gridlist").jqGrid("getGridParam", "selrow") || [];
	             if(rowId.length <=0){
	                $.HN.message.alert("<spring:message code="message.lable.pleaseSelectOperational"/><spring:message code="message.listForm.YaoLiFenLei"/><spring:message code="message.yanZheng.ganTanHao"/>", "<spring:message code="message.HN.alert.type"/>", "warn");
	                return;
	             }
	             var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
	             var dialog = top.dialog.get(window);
	             var params = {
	             	"pharName" : rowdata.pharName,
	             	"pharId" : rowdata.pharId,
	             	"pharCode" : rowdata.pharCode,
	             	"pharStatus" : 1
	             };
	             dialog.close(params);   // 关闭（隐藏）对话框
	             dialog.remove();        // 主动销毁对话框
	        }
	       
    </script>
</body>
</html>
